<template>
  <div id="index">
    <div class="tj-head clearfloat">
      <div class="info-box column-01">
        <span class="icon icon-01"><i class="fa fa-qrcode fa-3x" aria-hidden="true"></i></span>
        <a href="#">
          <div class="info-no">7</div>
          <div>固定资产总数 (台/套)</div>
        </a>
      </div>
      <div class="info-box column-02">
        <span class="icon icon-02"><i class="fa fa-yen fa-3x" aria-hidden="true"></i></span>
        <a href="#">
          <div class="info-no">0</div>
          <div>上次清点数量（台/套）</div>
        </a>
      </div>
    </div>

    <!--图标div所在位置-->
    <div class="charts-content">
      <div>
        <div id="chartByClassify" class="chart" :style="{width: '100%', height: '270px'}"></div>
      </div>
      <div>
        <div id="chartByDept" class="chart" :style="{width: '100%', height: '270px'}"></div>
      </div>

    </div>
    <!--这里是一系统首页-->
  </div>
</template>

<script>
  export default {
    name: "Index",
    data() {
      return {
        msg: 'Welcome to Your Vue.js App',
        chartData4Dept: {name:"111"}
      }
    },
    mounted() {
      this.drawLine();
    }
    ,
    methods: {
      drawLine() {
        // 基于准备好的dom，初始化echarts实例
        let chartByClassify = this.$echarts.init(document.getElementById('chartByClassify'));
        // 绘制图表
        chartByClassify.setOption({
          title: {text: '资产分布情况（按分类）'},
          tooltip: {},
          legend: {
            data: ['资产数量', '上次已清点数量']
          },
          xAxis: {
            data: ["打印机", "台式电脑", "笔记本电脑"]
          },
          yAxis: {},
          series: [{
            name: '资产数量',
            type: 'bar',
            data: [5, 20, 36]
          }, {
            name: '上次已清点数量',
            type: 'bar',
            data: [0, 0, 0]
          }]
        });

        // GET /someUrl
        this.$http.get('http://localhost:8080/static/json/test.json').then(response => {
        // this.$http.jsonp('http://localhost:8080/static/json/test.json').then(response => {

          // get body data
          this.chartData4Dept = response.body;

          let chartByDept = this.$echarts.init(document.getElementById('chartByDept'));
          let option = {
            title: {text: this.chartData4Dept.title},
            tooltip: {},
            legend: {
              data: this.chartData4Dept.legendData
            },
            xAxis: {
              data: this.chartData4Dept.xAxisData
            },
            yAxis: {},
            series: this.chartData4Dept.series
          }

          chartByDept.setOption(option);
          ()=>{

            console.log("=============>");
            console.log(this.chartData4Dept.title);
            console.log("=============>");
          }
        }, (err) => {
          // error callback
          console.log(err)
        });

      }
    }

  }
</script>

<style scoped>
  #index {
    background-color: #eee;
    padding: 0 10px;
  }

  .tj-head {
    height: 140px;
    width: 100%;
    /*box-sizing: border-box;*/
    overflow: hidden;
  }

  .tj-head .info-box {
    float: left;
    width: 49.4%;
    height: 100px;
    margin-top: 20px;
    background-color: #428bca;
  }

  .tj-head .column-01 {
    background-color: #428bca;
  }

  .tj-head .column-02 {
    background-color: #5cb85c;
    margin-left: 20px;
  }

  .tj-head .icon {
    width: 100px;
    height: 100px;
    display: inline-block;
  }

  .tj-head .icon-01 {
    background-color: #356fa2;
  }

  .tj-head .icon-02 {
    background-color: #4a934a;
  }

  .tj-head .icon i {
    /*border: 1px solid red;*/
    margin: 27px 28px;
    color: #fff;
  }

  .tj-head .icon-02 i {
    margin: 27px 32px;
  }

  .tj-head .info-box a {
    /*实现了宽度为父容器宽度减去固定的 100 + 16 像素*/
    width: -webkit-calc(100% - 116px);
    width: -moz-calc(100% - 116px);
    width: calc(100% - 116px);
    display: inline-block;
    padding-left: 10px;
    text-decoration: none;
    color: #fff;
    font-size: 18px;
    height: 100px;
  }

  .tj-head .info-box a .info-no {
    font-size: 30px;
  }

  .charts-content {
    /*border: 1px solid red;*/
  }

  .charts-content .chart {
    height: 270px;
    zoom: 1;
    box-shadow: rgba(0, 0, 0, 0.1) 1px 1.732px 6px 0px;
    margin: 0px 1% 15px 0px;
    overflow: auto;
    background: rgb(255, 255, 255);
    border: 1px solid rgb(221, 221, 221);
    /*border-image: initial;*/
  }
</style>
